<?php defined('SYSPATH') or die('No direct script access.');

class Include_Right {
	public static function right_content(){
		
		// 一周热门文章
		$Marticle = Model::factory('Article');
		$hot_articles = $Marticle->get_hot_one_week(8);
		foreach ($hot_articles as &$hot_article){
			$len_set = 14;
			if (UTF8::strlen($hot_article['title']) > $len_set){
				$hot_article['title_cut'] = UTF8::substr_replace($hot_article['title'], ' …', $len_set);
			}else {
				$hot_article['title_cut'] = $hot_article['title'];
			}
		}
			
		// 热门标签
		$Mtag = Model::factory('Tag');
		$hot_tag_arr = $Mtag->hot_tag(9);
		$hot_tags = array();
		foreach ($hot_tag_arr as $tags){
			$hot_tags[] = array(
					'tag_size' => $tags['rank'],
					'tag' => $tags['name'],
					'tagid' => $tags['id']
			);
		}
			
		// 最新评论
		$Mcomment = Model::factory('Comment');
		$new_comments = $Mcomment->get_list(0, 5);
		foreach ($new_comments as &$comment){
			switch ($comment['type']){
				case '1':
					$comment['nick'] = !empty($comment['user_nick']) ? $comment['user_nick'] : $comment['user'];
					break;
				case '2':
					// 待处理
					break;
				case '3':
					$comment['nick'] = !empty($comment['nick']) ? $comment['nick'] : '匿名';
					break;
				default:
					$comment['nick'] = '***';
			}
		}

		return array('hot_articles' => $hot_articles, 'hot_tags' => $hot_tags, 'new_comments' => $new_comments);
	}
}